package de.unidue.masterproject.plugin;

import javax.swing.JInternalFrame;
import javax.swing.JTextArea;

import de.unidue.masterproject.plugin.classes_literaturplugin.Article;
import de.unidue.masterproject.plugin.classes_literaturplugin.ArticleQuote;
import de.unidue.masterproject.plugin.classes_literaturplugin.Book;
import de.unidue.masterproject.plugin.classes_literaturplugin.BookQuote;
import de.unidue.masterproject.plugin.classes_literaturplugin.Literature;
import de.unidue.masterproject.plugin.classes_literaturplugin.Quote;
import de.unidue.masterproject.plugin.classes_literaturplugin.Website;

public class DisplayArea {
	private JTextArea textDisplayArea;
	
	public DisplayArea(int x, int y,  int width, int height, JInternalFrame frame){
		textDisplayArea = new JTextArea();
		textDisplayArea.setBounds(x, y, width, height);
		textDisplayArea.setEditable(false);
		frame.add(textDisplayArea);
	}
	
	public void show(Object content){
		System.out.println("Show():"+content);
		if(content == null){
			textDisplayArea.setText("There is nothing to be showen for this element...");
		}
		else if(content instanceof String){
			textDisplayArea.setText("Double click on this element to expand it!");
		}
		else if(content instanceof Literature){
			showLiterature((Literature)content);
		}
		else{
			showQuote((Quote)content);
		}
		
	}
	
	private void showLiterature(Literature literature){
		String s;
		
		s = "Author:\n\t"+literature.getAuthor()+"\n";
		s += "Title:\n\t"+literature.getTitle()+"\n";
		s += "Year:\n\t"+literature.getYear()+"\n";
		
		if(literature instanceof Article){
			Article article = (Article)literature;
			s += "Magazine:\n\t"+article.getMagazine()+"\n";
			s += "Pages:\n\t"+article.getPages()+"\n";
		}
		else if(literature instanceof Book){
			Book book = (Book)literature;
			s += "Edition:\n\t"+book.getEdition()+"\n";
			s += "Town:\n\t"+book.getTown()+"\n";
		}
		else if(literature instanceof Website){
			Website website = (Website)literature;
			s += "URL:\n\t"+website.getUrl()+"\n";
			s += "Last request:\n\t"+website.getDate()+"\n";
		}
		
		s += "Comment:\n"+literature.getComment()+"\n";
		
		textDisplayArea.setText(s);
	}
	
	private void showQuote(Quote quote){
		String s="Quote";
		
		s = "Content:\n"+quote.getContent()+"\n\n";
		s += "Comment:\n"+quote.getComment()+"\n\n";
		
		if(quote instanceof ArticleQuote){
			ArticleQuote aQ = (ArticleQuote)quote;
			s += "Pages:\n\t"+aQ.getPages()+"\n";
		}
		else if(quote instanceof BookQuote){
			BookQuote bQ = (BookQuote)quote;
			s += "Pages:\n\t"+bQ.getPages()+"\n";
		}
		
		s += "Owner:\n\t"+quote.getOwner()+"\n";
		s += "Shared with other users:\n\t"+quote.isPublished()+"\n";
		
		textDisplayArea.setText(s);
	}
	
}
